package basics;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public abstract class OperacoesEmArquivo {

	public static ArrayList<String> leitura(String path) throws IOException {
		ArrayList<String> strings = new ArrayList<String>();
		BufferedReader br;

		br = new BufferedReader(new FileReader(path));
		while (br.ready()) {
			strings.add(br.readLine());
		}
		br.close();

		return strings;
	}

	public static void escrita(String path, ArrayList<String> strings) throws IOException {

		BufferedWriter bw;

		bw = new BufferedWriter(new FileWriter(path));
		bw.write(strings.get(0));
		for (int i = 1; i < strings.size(); i++) {
			bw.newLine();
			bw.write(strings.get(i));
		}
		bw.close();

	}

	public static void escrita(String path, String string) throws IOException {

		BufferedWriter bw;

		bw = new BufferedWriter(new FileWriter(path));
		bw.write(string);
		bw.close();
	}

}
